﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMS.Entity;

namespace CMS.DAL
{
    public class BussinessProfileListDAL
    {
        public List<BussinessProfileList> GetLst(string stock, DateTime endDate)
        {
            string sql = "select * from BussinessProfileList where stock=@stock and EndDate=@EndDate";
            Tools tool = new Tools();
            tool.AddSqlParameter("stock", System.Data.SqlDbType.VarChar, stock);
            tool.AddSqlParameter("EndDate", System.Data.SqlDbType.DateTime, endDate);
            return SqlHelper.GetDataByColumnsLst<BussinessProfileList>(DBConn.gaInfo, sql, tool.GetSqlParameters());
        }

        public void Add(BussinessProfileList c)
        {
            string sql = "INSERT INTO [BussinessProfileList] ([Stock] ,[EndDate] ,[Item] ,[Content] ,[RecTime] ,[ModTime]) VALUES (@Stock ,@EndDate ,@Item ,@Content ,@RecTime ,@ModTime)";
            var sps = SqlHelper.ObjectToSqlParameters(c);
            SqlHelper.ExecuteNonQuery(DBConn.gaInfo, System.Data.CommandType.Text, sql, sps);
        }

        public void Update(BussinessProfileList c)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("UPDATE [BussinessProfileList]");
            sb.AppendLine("   SET [Content] = @Content");
            sb.AppendLine("      ,[Item]=@Item");
            sb.AppendLine("      ,[Stock] = @Stock");
            sb.AppendLine("      ,[EndDate] = @EndDate");
            sb.AppendLine("      ,[RecTime] = @RecTime");
            sb.AppendLine("      ,[ModTime] = @ModTime");
            sb.AppendLine(" WHERE [Id]=@Id");
            var sps = SqlHelper.ObjectToSqlParameters(c);
            SqlHelper.ExecuteNonQuery(DBConn.gaInfo, System.Data.CommandType.Text, sb.ToString(), sps);
        }

        public BussinessProfileList GetOne(long id)
        {
            string sql = "select * from BussinessProfileList where Id=@id";
            Tools tool = new Tools();
            tool.AddSqlParameter("id", System.Data.SqlDbType.BigInt, id);
            return SqlHelper.GetDataByColumns<BussinessProfileList>(DBConn.gaInfo, sql, tool.GetSqlParameters());
        }

        public void Delete(long id)
        {
            string sql = "delete from BussinessProfileList where id=@id";
            Tools tool = new Tools();
            tool.AddSqlParameter("id", System.Data.SqlDbType.BigInt, id);
            SqlHelper.ExecuteNonQuery(DBConn.gaInfo, System.Data.CommandType.Text, sql, tool.GetSqlParameters());
        }
    }
}
